package com.stylefeng.guns.modular.system.controller;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.google.common.base.Splitter;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.node.ZTreeNode;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.area.dao.BdapAreaCellRefMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaMapper;
import com.stylefeng.guns.modular.area.dao.BdapAreaPopPropHmMapper;
import com.stylefeng.guns.modular.area.dao.BdapCellPopPropHmMapper;
import com.stylefeng.guns.modular.area.dao.BdapSubAreaMapper;
import com.stylefeng.guns.modular.area.dao.BdapUserAreaMapper;
import com.stylefeng.guns.modular.area.model.BdapArea;
import com.stylefeng.guns.modular.area.model.BdapAreaPopPropHm;
import com.stylefeng.guns.modular.area.model.BdapSubArea;
import com.stylefeng.guns.modular.area.model.BdapUserArea;
import com.stylefeng.guns.modular.area.util.AreaUtil;
import com.stylefeng.guns.modular.system.dao.NoticeDao;
import com.stylefeng.guns.modular.util.CityCodeUtil;
import com.stylefeng.guns.modular.util.StringUtil;

/**
 * 
 * ClassName: BlackboardController
 * 
 * @Description: TODO 系统首页
 * @author xiongyao
 * @date 2017年11月16日
 */
@Controller
@RequestMapping("/blackboard")
public class BlackboardController extends BaseController {

	@Autowired
	NoticeDao noticeDao;

	/**
	 * 用户区域授权表mapper
	 */
	@Autowired
	BdapUserAreaMapper userAreaMapper;
	/**
	 * 区域表mapper
	 */
	@Autowired
	BdapAreaMapper areaMapper;
	/**
	 * 子区域表mapper
	 */
	@Autowired
	BdapSubAreaMapper subareaMapper;

	/**
	 * 区域实时表mapper
	 */
	@Autowired
	BdapAreaPopPropHmMapper areaPopPropHmMapper;

	/**
	 * 小区小时表mapper
	 */
	@Autowired
	BdapCellPopPropHmMapper cellHourMapper;

	/**
	 * 区域基站关系表mapper
	 */
	@Autowired
	BdapAreaCellRefMapper areaCellMapper;

	BdapAreaPopPropHm largestUcArea = new BdapAreaPopPropHm();// 人数最多区域
	BdapAreaPopPropHm largestSWUcArea = new BdapAreaPopPropHm();// 外省人数最多区域
	BdapAreaPopPropHm largestMoveUcArea = new BdapAreaPopPropHm();// 人口流动最大区域
	BdapAreaPopPropHm followArea = new BdapAreaPopPropHm();// 特别关注区域区域

	/**
	 * 跳转到首页
	 */
	@RequestMapping("")
	public String blackboard(Model model) {
		// 判断用户是否是管理员
		// 查询用户区域授权表
		// 如果是管理员，1.遍历用户区域授权表，看管理员是否有关注区域，查询所有的区域，根据区域查询子区域，根据子区域的LAC,CI去查询小区实时。
		// 如果是普通用户。1.遍历用户区域授权表，查询用户授权区域还有关注区域，然后根据区域查询子区域，根据子区域的LAC,CI去查询小区实时。
		// 查询小区数据的最新数据时间。
		List<BdapUserArea> userAreaList = userAreaMapper
				.selectList(new EntityWrapper<BdapUserArea>().eq("USERID",
						ShiroKit.getUser().getId() + ""));// 用户授权区域
		List<Long> userAreaIds = new ArrayList<Long>();
		long followAreaId = 0l;
		if (!userAreaList.isEmpty()) {
			for (BdapUserArea userArea : userAreaList) {
				if (BdapUserArea.IS_IMPORTANT.equals(userArea.getIsImportant())) {
					followAreaId = userArea.getAreaid();
				}
				userAreaIds.add(userArea.getAreaid());
			}
		}
		List<BdapArea> areaList = new ArrayList<BdapArea>();// 区域数据
		List<String> areaIds = new ArrayList<String>();// 区域ID集合
		String timeThreeDayAgo = LocalDateTime.now().minusDays(-3)
				.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
		String maxTime = sdf.format(new Date());
		String maxTimeBefor = null;
		// List<Object> times = cellHourMapper.selectObjs(new
		// EntityWrapper<BdapCellPopPropHm>(.setSqlSelect("max(STAT_HOUR)").ge("STAT_HOUR",timeThreeDayAgo));

		List<Object> times = areaPopPropHmMapper
				.selectObjs(new EntityWrapper<BdapAreaPopPropHm>()
						.setSqlSelect("max(STAT_HOUR)").ge("STAT_HOUR",
								timeThreeDayAgo));

		if (times.get(0) == null) {
			// List<Object> timess = cellHourMapper
			// .selectObjs(new EntityWrapper<BdapCellPopPropHm>()
			// .setSqlSelect("max(STAT_HOUR)"));
			List<Object> timess = areaPopPropHmMapper
					.selectObjs(new EntityWrapper<BdapAreaPopPropHm>()
							.setSqlSelect("max(STAT_HOUR)"));
			if (timess.get(0) != null) {
				System.out.println(timess.get(0).toString());
				maxTime = timess.get(0).toString();
			} else {
				maxTime = LocalDateTime.now().format(
						DateTimeFormatter.ofPattern("yyyyMMddHH"));
			}
		} else {
			maxTime = times.get(0).toString();
		}
		maxTimeBefor = LocalDateTime
				.of(Integer.parseInt(maxTime.substring(0, 4)),
						Integer.parseInt(maxTime.substring(4, 6)),
						Integer.parseInt(maxTime.substring(6, 8)),
						Integer.parseInt(maxTime.substring(8, 10)), 0)
				.plusHours(-1)
				.format(DateTimeFormatter.ofPattern("yyyyMMddHH")).toString();
		Map<String, BdapAreaPopPropHm> areaDataMap = new HashMap<String, BdapAreaPopPropHm>();// K区域ID，V区域数据
		Map<String, BdapAreaPopPropHm> areaDataMapBefore = new HashMap<String, BdapAreaPopPropHm>();// K区域ID，V区域数据
		Map<String, BdapArea> bdapAreaMap = new HashMap<String, BdapArea>();// K区域ID，V区域设置数据

		// 根据用户角色获取区域人流信息
		if (ShiroKit.isAdmin()) {
			areaList = areaMapper.selectList(new EntityWrapper<BdapArea>());
			for (BdapArea area : areaList) {
				areaIds.add(area.getId().toString());
			}
			// List<BdapAreaPopPropHm> areaDatas =
			// areaPopPropHmMapper.selectAreaCellDataHmList(maxTime, "");

			List<BdapAreaPopPropHm> areaDatas = areaPopPropHmMapper
					.selectList(new EntityWrapper<BdapAreaPopPropHm>().eq(
							"STAT_HOUR", maxTime));
			for (int i = 0; i < areaDatas.size(); i++) {
				areaDataMap.put(areaDatas.get(i).getAreaid(), areaDatas.get(i));
			}
			// List<BdapAreaPopPropHm> areaDataBefores =
			// areaPopPropHmMapper.selectAreaCellDataHmList(maxTimeBefor, "");
			List<BdapAreaPopPropHm> areaDataBefores = areaPopPropHmMapper
					.selectList(new EntityWrapper<BdapAreaPopPropHm>().eq(
							"STAT_HOUR", maxTimeBefor));
			for (int i = 0; i < areaDataBefores.size(); i++) {
				areaDataMapBefore.put(areaDataBefores.get(i).getAreaid(),
						areaDataBefores.get(i));
			}
		} else {
			if (userAreaIds.size() > 0 && userAreaIds.get(0) != null) {
				areaList = areaMapper.selectList(new EntityWrapper<BdapArea>()
						.in("ID", userAreaIds));
				for (BdapArea area : areaList) {
					areaIds.add(area.getId().toString());
				}
				if (!areaIds.isEmpty() && areaIds.get(0) != null) {
					// List<BdapAreaPopPropHm> areaDatas =
					// areaPopPropHmMapper.selectAreaCellDataHmList(maxTime,StringUtil.concat(areaIds));
					List<BdapAreaPopPropHm> areaDatas = areaPopPropHmMapper
							.selectList(new EntityWrapper<BdapAreaPopPropHm>()
									.in("AREAID", areaIds).eq("STAT_HOUR",
											maxTime));
					for (int i = 0; i < areaDatas.size(); i++) {
						areaDataMap.put(areaDatas.get(i).getAreaid(),
								areaDatas.get(i));
					}
					// List<BdapAreaPopPropHm> areaDataBefores =
					// areaPopPropHmMapper.selectAreaCellDataHmList(maxTimeBefor,StringUtil.concat(areaIds));
					List<BdapAreaPopPropHm> areaDataBefores = areaPopPropHmMapper
							.selectList(new EntityWrapper<BdapAreaPopPropHm>()
									.in("AREAID", areaIds).eq("STAT_HOUR",
											maxTimeBefor));
					for (int i = 0; i < areaDataBefores.size(); i++) {
						areaDataMapBefore.put(areaDataBefores.get(i)
								.getAreaid(), areaDataBefores.get(i));
					}
				}
			}
		}
		for (BdapArea area : areaList) {
			bdapAreaMap.put(area.getId() + "", area);
		}

		List<BdapArea> watchAreaList = new ArrayList<BdapArea>();// 监控区域
		List<BdapArea> warnAreaList = new ArrayList<BdapArea>();// 警戒区域
		List<BdapArea> saturatedAreaList = new ArrayList<BdapArea>();// 饱和区域
		List<BdapArea> seriousAreaList = new ArrayList<BdapArea>();// 严重区域
		long largestAreaTotalUserCount = 0l;
		long largestSwUserCounts = 0l;
		long warnValue;// 警戒告警人数
		long saturatedwarnValue;// 饱和告警人数
		long seriouswarnValue;// 严重告警人数
		BdapArea bdapArea = new BdapArea();
		for (Entry<String, BdapAreaPopPropHm> entry : areaDataMap.entrySet()) {
			BdapAreaPopPropHm thisArea = entry.getValue();
			if (null != thisArea && thisArea.getTotalUsers() != null
					&& thisArea.getSwCityUsers() != null) {
				bdapArea = bdapAreaMap.get(entry.getKey());
				warnValue = Long.parseLong(StringUtil.ifNullOrEmptyDefault(
						bdapArea.getWarningValue() + "", "5000"));
				saturatedwarnValue = Long.parseLong(StringUtil
						.ifNullOrEmptyDefault(bdapArea.getSaturationValue()
								+ "", "10000"));
				seriouswarnValue = Long.parseLong(StringUtil
						.ifNullOrEmptyDefault(bdapArea.getSevereValue() + "",
								"20000"));
				watchAreaList.add(bdapAreaMap.get(thisArea.getAreaid()));
				long areaTotalUserCount = 0l;
				if (thisArea.getTotalUsers() == null
						|| thisArea.getTotalUsers() == ""
						|| thisArea.getTotalUsers().equals("null")) {
					areaTotalUserCount = 0l;
				} else {
					areaTotalUserCount = Long.parseLong(thisArea
							.getTotalUsers());
				}
				long swUserCounts = 0l;
				String[] swCitys = thisArea.getSwCityUsers().split(";");
				for (String swCity : swCitys) {
					try {
						if (swCity.split(":").length > 1) {
							swUserCounts = swUserCounts + Long.parseLong("2");
						}
					} catch (Exception e) {
						// e.printStackTrace();
						// TODO: handle exception
						System.out.println("=========================="
								+ Splitter.on(':').splitToList(swCity).get(1));
						// System.out.println(Splitter.on(':').splitToList(swCity).get(1).getClass());
					}
				}
				// 判断人数最多
				if (areaTotalUserCount >= largestAreaTotalUserCount) {
					largestAreaTotalUserCount = areaTotalUserCount;
					largestUcArea = thisArea;
					largestMoveUcArea = thisArea;
				}
				// 判断外省人数最多
				if (swUserCounts >= largestSwUserCounts) {
					largestSwUserCounts = swUserCounts;
					largestSWUcArea = thisArea;
				}
				if (thisArea.getAreaid().equals(Long.toString(followAreaId))) {
					followArea = thisArea;
				}

				// 如果大于严重告警人数
				if (areaTotalUserCount >= seriouswarnValue) {
					seriousAreaList.add(bdapAreaMap.get(thisArea.getAreaid()));
					continue;
				}

				// 如果大于饱和告警人数
				if (areaTotalUserCount >= saturatedwarnValue) {
					saturatedAreaList
							.add(bdapAreaMap.get(thisArea.getAreaid()));
					continue;
				}

				// 如果大于警戒告警人数
				if (areaTotalUserCount >= warnValue) {
					warnAreaList.add(bdapAreaMap.get(thisArea.getAreaid()));
					continue;
				}
			}
		}

		// =================================================把数据往model里面放=========================================================
		// 监控区域
		model.addAttribute("monitorArea", watchAreaList);
		model.addAttribute("monitorAreaNum", watchAreaList.size());
		// 告警区域
		model.addAttribute("warnArea", warnAreaList);
		model.addAttribute("warnAreaNum", warnAreaList.size());
		// 饱和区域
		model.addAttribute("saturatedwarnArea", saturatedAreaList);
		model.addAttribute("saturatedwarnAreaNum", saturatedAreaList.size());
		// 严重区域
		model.addAttribute("seriouswarnArea", seriousAreaList);
		model.addAttribute("seriouswarnAreaNum", seriousAreaList.size());

		String followAreaName = "暂无关注";
		if (null != followArea.getAreaid()
				&& areaList.stream().anyMatch(
						(BdapArea area) -> area.getId() == Long
								.parseLong(followArea.getAreaid()))) {
			followAreaName = areaList
					.stream()
					.filter((BdapArea area) -> area.getId() == Long
							.parseLong(followArea.getAreaid())).findFirst()
					.get().getName();
		}

		// 特别关注区域区域
		model.addAttribute("importantAreaName", followAreaName);// 特别关注区域的名称
		model.addAttribute("importantAreaId",
				StringUtil.ifNullOrEmptyDefault(followArea.getAreaid(), ""));// 特别关注区域的ID
		model.addAttribute("importantAreaPassengerCount", StringUtil
				.ifNullOrEmptyDefault(followArea.getTotalUsers(), "暂无"));// 特别关注区域的实时用户数
		model.addAttribute("importantAreaPassengerDensity", AreaUtil
				.getPassengerDensity(bdapAreaMap.get(StringUtil
						.ifNullOrEmptyDefault(followArea.getAreaid(), "暂无")),
						followArea));// 客流密度
		model.addAttribute(
				"importantAreaPassengerDensityForecast",
				AreaUtil.getNextHourUc(followArea,
						areaDataMapBefore.get(followArea.getAreaid())));// 未来一小时客流密度预测
		model.addAttribute(
				"importantAreaPassengerSpeedUp",
				AreaUtil.getPassengerFlowGrowth(followArea,
						areaDataMapBefore.get(followArea.getAreaid())));// 客流增速
		model.addAttribute("importantAreaWarnLevel", AreaUtil.getWarnLevel(
				bdapAreaMap.get(followArea.getAreaid()), followArea));// 告警级别
		String maxMobilityAreaName = "暂无";
		if (null != largestUcArea.getAreaid()
				&& areaList.stream().anyMatch(
						(BdapArea area) -> area.getId() == Long
								.parseLong(largestUcArea.getAreaid()))) {
			maxMobilityAreaName = areaList
					.stream()
					.filter((BdapArea area) -> area.getId() == Long
							.parseLong(largestUcArea.getAreaid())).findAny()
					.get().getName();
		}
		// 人数最多区域
		model.addAttribute("maxMobilityAreaName", maxMobilityAreaName);
		model.addAttribute("maxMobilityAreaId",
				StringUtil.ifNullOrEmptyDefault(largestUcArea.getAreaid(), ""));// 人数最多区域的ID
		model.addAttribute("maxMobilityAreaPassengerCount", StringUtil
				.ifNullOrEmptyDefault(largestUcArea.getTotalUsers(), "暂无"));// 特别关注区域的实时用户数
		model.addAttribute("maxMobilityAreaPassengerDensity", AreaUtil
				.getPassengerDensity(
						bdapAreaMap.get(StringUtil.ifNullOrEmptyDefault(
								largestUcArea.getAreaid(), "暂无")),
						largestUcArea));// 客流密度
		model.addAttribute(
				"maxMobilityAreaPassengerDensityForecast",
				AreaUtil.getNextHourUc(largestUcArea,
						areaDataMapBefore.get(largestUcArea.getAreaid())));// 未来一小时客流密度预测
		model.addAttribute("maxMobilityAreaPassengerSpeedUp", AreaUtil
				.getPassengerFlowGrowth(largestUcArea,
						areaDataMapBefore.get(largestUcArea.getAreaid())));// 客流增速
		model.addAttribute("maxMobilityAreWarnLevel", AreaUtil.getWarnLevel(
				bdapAreaMap.get(largestUcArea.getAreaid()), largestUcArea));// 告警级别
		String maxPassengerDensityAreaName = "暂无";
		if (null != largestMoveUcArea.getAreaid()
				&& areaList.stream().anyMatch(
						(BdapArea area) -> area.getId() == Long
								.parseLong(largestMoveUcArea.getAreaid()))) {
			maxPassengerDensityAreaName = areaList
					.stream()
					.filter((BdapArea area) -> area.getId().toString()
							.equals(largestMoveUcArea.getAreaid())).findAny()
					.get().getName();
		}
		// 人口流动最大区域
		model.addAttribute("maxPassengerDensityAreaName",
				maxPassengerDensityAreaName);
		model.addAttribute("maxPassengerDensityAreaId", StringUtil
				.ifNullOrEmptyDefault(largestMoveUcArea.getAreaid(), ""));
		model.addAttribute(
				"maxPassengerDensityAreaPassengerCount",
				StringUtil.ifNullOrEmptyDefault(
						largestMoveUcArea.getTotalUsers(), "暂无"));// 特别关注区域的实时用户数
		model.addAttribute("maxPassengerDensityAreaPassengerDensity", AreaUtil
				.getPassengerDensity(bdapAreaMap.get(StringUtil
						.ifNullOrEmptyDefault(largestMoveUcArea.getAreaid(),
								"暂无")), largestMoveUcArea));// 客流密度
		model.addAttribute(
				"maxPassengerDensityAreaPassengerDensityForecast",
				AreaUtil.getNextHourUc(largestMoveUcArea,
						areaDataMapBefore.get(largestMoveUcArea.getAreaid())));// 未来一小时客流密度预测
		model.addAttribute("maxPassengerDensityAreaPassengerSpeedUp", AreaUtil
				.getPassengerFlowGrowth(largestMoveUcArea,
						areaDataMapBefore.get(largestMoveUcArea.getAreaid())));// 客流增速
		model.addAttribute("maxPassengerDensityAreaWarnLevel", AreaUtil
				.getWarnLevel(bdapAreaMap.get(largestMoveUcArea.getAreaid()),
						largestMoveUcArea));// 告警级别
		String maxExternalPassengerAreaName = "暂无";
		if (null != largestSWUcArea.getAreaid()
				&& areaList.stream().anyMatch(
						(BdapArea area) -> area.getId() == Long
								.parseLong(largestSWUcArea.getAreaid()))) {
			maxExternalPassengerAreaName = areaList
					.stream()
					.filter((BdapArea area) -> area.getId().toString()
							.equals(largestSWUcArea.getAreaid())).findAny()
					.get().getName();
		}
		// 外省人数最多区域
		model.addAttribute("maxExternalPassengerAreaName",
				maxExternalPassengerAreaName);
		model.addAttribute("maxExternalPassengerAreaId", StringUtil
				.ifNullOrEmptyDefault(largestSWUcArea.getAreaid(), ""));
		model.addAttribute("maxExternalPassengerAreaPassengerCount", StringUtil
				.ifNullOrEmptyDefault(largestSWUcArea.getTotalUsers(), "暂无"));// 特别关注区域的实时用户数
		model.addAttribute("maxExternalPassengerAreaPassengerDensity", AreaUtil
				.getPassengerDensity(
						bdapAreaMap.get(StringUtil.ifNullOrEmptyDefault(
								largestSWUcArea.getAreaid(), "暂无")),
						largestSWUcArea));// 客流密度
		model.addAttribute(
				"maxExternalPassengerAreaPassengerDensityForecast",
				AreaUtil.getNextHourUc(largestSWUcArea,
						areaDataMapBefore.get(largestSWUcArea.getAreaid())));// 未来一小时客流密度预测
		model.addAttribute("maxExternalPassengerAreaPassengerSpeedUp", AreaUtil
				.getPassengerFlowGrowth(largestSWUcArea,
						areaDataMapBefore.get(largestSWUcArea.getAreaid())));// 客流增速
		model.addAttribute("maxExternalPassengerAreaWarnLevel", AreaUtil
				.getWarnLevel(bdapAreaMap.get(largestSWUcArea.getAreaid()),
						largestSWUcArea));// 告警级别

		if (null == maxTime || "" == maxTime) {
			maxTime = sdf.format(new Date());
		}
		model.addAttribute(
				"dataTime",
				LocalDateTime.parse(maxTime,
						DateTimeFormatter.ofPattern("yyyyMMddHH")).format(
						DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时")));
		return "/blackboard.html";
	}

	/**
	 * 获取授权区域的tree列表
	 */
	@RequestMapping(value = "/tree")
	@ResponseBody
	public List<ZTreeNode> tree() {
		List<ZTreeNode> zTreeNodes = new ArrayList<ZTreeNode>();// ZTree结构
		Wrapper<BdapUserArea> userAreaWrapper = new EntityWrapper<BdapUserArea>();// 用户区域查询条件类
		List<BdapArea> areaList = new ArrayList<BdapArea>();// 区域表
		List<BdapSubArea> subAreaList = new ArrayList<BdapSubArea>();
		Map<String, String> cityMap = new HashMap<String, String>();// 存放地市
		Wrapper<BdapArea> areaWrapper = new EntityWrapper<BdapArea>();
		Wrapper<BdapSubArea> subAreaWrapper = new EntityWrapper<BdapSubArea>();
		List<Long> areaIds = new ArrayList<Long>();
		// 如果是管理员，可以查看所有的区域
		int userId = ShiroKit.getUser().getId();// 当前用户ID
		userAreaWrapper.eq("USERID", userId);
		List<BdapUserArea> userAreaList = userAreaMapper
				.selectList(userAreaWrapper);// 用户授权的区域ID
		// 根据用户授权区域，查询区域下的子区域
		if (userAreaList.size() > 0) {
			for (BdapUserArea area : userAreaList) {
				areaIds.add(area.getAreaid());
			}
			subAreaWrapper.in("PID", areaIds);
			areaWrapper.in("ID", areaIds);
			subAreaList = subareaMapper.selectList(subAreaWrapper);
			areaList = areaMapper.selectList(areaWrapper);
		}
		if (ShiroKit.isAdmin()) {
			areaWrapper = new EntityWrapper<BdapArea>();
			subAreaWrapper = new EntityWrapper<BdapSubArea>();
			subAreaList = subareaMapper.selectList(subAreaWrapper);
			areaList = areaMapper.selectList(areaWrapper);
		}
		// 根据地市，区域和子区域的关系，按照前端要求，封装成树形结构
		int i = 0;
		for (BdapArea area : areaList) {
			ZTreeNode treeNode = new ZTreeNode();
			if (!cityMap.containsKey(area.getCity())) {
				ZTreeNode cityNode = new ZTreeNode();
				cityMap.put(area.getCity(),
						CityCodeUtil.getCityCode(area.getCity()));
				cityNode.setId(Long.parseLong(cityMap.get(area.getCity())));
				cityNode.setpId(0l);
				cityNode.setName(area.getCity());
				zTreeNodes.add(cityNode);
			}
			if (i == 0) {
				treeNode.setChecked(true);
			}
			i++;
			treeNode.setId(area.getId());
			treeNode.setpId(Long.parseLong(cityMap.get(area.getCity())));
			treeNode.setName(area.getName());
			zTreeNodes.add(treeNode);
		}

		for (BdapSubArea subArea : subAreaList) {
			ZTreeNode treeNode = new ZTreeNode();
			treeNode.setId(subArea.getId());
			treeNode.setpId(subArea.getPid());
			treeNode.setName(subArea.getName());
			zTreeNodes.add(treeNode);
		}
		return zTreeNodes;
	}
}
